import instance from '../utils/request'
import qs from 'qs'
import { Message } from 'element-ui'

// User修改提交
async function editClean (clean) {
  return await instance({
    url: 'checkclean',
    method: 'put',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(clean)
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('修改失败,服务器错误!')
  })
}

// User修改提交
async function addClean (clean) {
  return await instance({
    url: 'checkclean',
    method: 'post',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(clean)
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('修改失败,服务器错误!')
  })
}

// 得到所有记录
async function getClean (page, limit, search) {
  return await instance.get('/checkclean/getCleans?page=' + page + '&limit=' + limit + '&cleanName=' + search).then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}

// 删除宿管
async function deleteClean (cleanId) {
  return await instance.delete('/checkclean/' + cleanId).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

// 删除宿管
async function deleteAllClean (cleanId) {
  return await instance.delete('/checkclean/all/' + cleanId).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

export default {
  editClean,
  getClean,
  deleteClean,
  deleteAllClean,
  addClean
}
